@model IEnumerable<UpdaterManagement.Models.User>

<nav aria-label="breadcrumb" class="breadcrumb-ace">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/">首页</a></li>
        <li class="breadcrumb-item active">用户管理</li>
    </ol>
</nav>

<div class="page-header">
    <div class="d-flex justify-content-between align-items-center">
        <div>
            <h1 class="page-title">
                <i class="bi bi-people text-primary me-2"></i>用户管理
            </h1>
            <p class="page-subtitle">管理系统用户账户和权限</p>
        </div>
        <a href="/User/Create" class="btn btn-ace-primary">
            <i class="bi bi-plus-circle me-2"></i>新增用户
        </a>
    </div>
</div>

<div class="row mb-4">
    <div class="col-xl-4 col-md-6">
        <div class="stat-card">
            <div class="stat-icon text-primary">
                <i class="bi bi-people"></i>
            </div>
            <div class="stat-number text-primary">@ViewBag.TotalCount</div>
            <div class="stat-label">总用户数</div>
        </div>
    </div>
    <div class="col-xl-4 col-md-6">
        <div class="stat-card">
            <div class="stat-icon" style="color: var(--ace-success);">
                <i class="bi bi-person-check"></i>
            </div>
            <div class="stat-number" style="color: var(--ace-success);">@Model.Count(u => u.Role == "Admin")</div>
            <div class="stat-label">管理员</div>
        </div>
    </div>
    <div class="col-xl-4 col-md-6">
        <div class="stat-card">
            <div class="stat-icon" style="color: var(--ace-info);">
                <i class="bi bi-person"></i>
            </div>
            <div class="stat-number" style="color: var(--ace-info);">@Model.Count(u => u.Role == "User")</div>
            <div class="stat-label">普通用户</div>
        </div>
    </div>
</div>

@if (Model.Any())
{
    <div class="card-ace">
        <div class="card-header">
            <i class="bi bi-table me-2"></i>用户列表
            <span class="badge badge-ace-secondary ms-2">@ViewBag.TotalCount 个用户</span>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-ace mb-0">
                    <thead>
                        <tr>
                            <th>用户信息</th>
                            <th>角色</th>
                            <th>邮箱</th>
                            <th>最后登录</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        {
                            <tr>
                                <td>
                                    <div>
                                        <strong class="text-dark">@item.RealName</strong>
                                        <br><small class="text-muted">@item.Username</small>
                                    </div>
                                </td>
                                <td>
                                    @if (item.Role == "Admin")
                                    {
                                        <span class="badge badge-ace-danger">
                                            <i class="bi bi-shield-check me-1"></i>管理员
                                        </span>
                                    }
                                    else
                                    {
                                        <span class="badge badge-ace-secondary">
                                            <i class="bi bi-person me-1"></i>普通用户
                                        </span>
                                    }
                                </td>
                                <td>
                                    @if (!string.IsNullOrEmpty(item.Email))
                                    {
                                        <span>@item.Email</span>
                                    }
                                    else
                                    {
                                        <span class="text-muted">未设置</span>
                                    }
                                </td>
                                <td>
                                    @if (item.LastLoginTime.HasValue)
                                    {
                                        <small class="text-muted">@item.LastLoginTime.Value.ToString("MM-dd HH:mm")</small>
                                    }
                                    else
                                    {
                                        <span class="text-muted">从未登录</span>
                                    }
                                </td>
                                <td>
                                    <small class="text-muted">@item.CreatedTime.ToString("yyyy-MM-dd")</small>
                                </td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <a href="/User/Edit/@item.Id" class="btn btn-outline-primary btn-sm" title="编辑用户">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        @if (item.Username != "admin")
                                        {
                                            <form method="post" action="/User/Delete/@item.Id" class="d-inline">
                                                <button type="button" class="btn btn-outline-danger btn-sm" title="删除用户" 
                                                        onclick="showDeleteConfirm('@item.RealName', this.form)">
                                                    <i class="bi bi-trash"></i>
                                                </button>
                                            </form>
                                        }
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
        
        <partial name="_Pagination" />
    </div>
}
else
{
    <div class="text-center py-5">
        <div class="mb-3">
            <i class="bi bi-people" style="font-size: 48px; color: #ccc;"></i>
        </div>
        <h5 class="text-muted">暂无用户数据</h5>
        <p class="text-muted">请点击上方按钮添加第一个用户</p>
        <a href="/User/Create" class="btn btn-ace-primary">
            <i class="bi bi-plus-circle me-2"></i>立即添加
        </a>
    </div>
}